﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using StartEAS_API.Utils;
using StartsEAS_API.BLL.Interfaces.IRegionalB;
using StartsEAS_API.Model;

namespace StartsEAS_API.Controllers.RegionalContor
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [EnableCors("any")]
    public class RegionalController : ControllerBase
    {

        private readonly IRegionalBLL _regionalBll;

        public RegionalController(IRegionalBLL regionalBll) { 
            _regionalBll = regionalBll;
        }
        /// <summary>
        /// 查询所有省份
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetAllProvince() {
            try
            {
                return _regionalBll.GetAllProvince();
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetAllProvince服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据省区域码查询省份
        /// </summary>
        /// <param name="ProvinceCode">省区域码</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetProvincByProvinceCode(int ProvinceCode) {
            try
            {
                return _regionalBll.GetProvincByProvinceCode(ProvinceCode);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetProvincByProvinceCode服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据省名称查询省份
        /// </summary>
        /// <param name="ProvinceName">省名称</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetProvincByProvinceName(string ProvinceName) {
            try
            {
                return _regionalBll.GetProvincByProvinceName(ProvinceName);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetProvincByProvinceName服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据省区域码查询市
        /// </summary>
        /// <param name="ProvinceCode">省区域码</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetCity(int ProvinceCode) {
            try
            {
                return _regionalBll.GetCity(ProvinceCode);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetCity服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据市区域码查询市
        /// </summary>
        /// <param name="CityCode">市区域码</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetCityByCityCode(int CityCode) {
            try
            {
                return _regionalBll.GetCityByCityCode(CityCode);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetCityByCityCode服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据市名查询市信息
        /// </summary>
        /// <param name="CityName">市名称</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetCityByCityName(string CityName) {
            try
            {
                return _regionalBll.GetCityByCityName(CityName);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetCityByCityName服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据市区域码查询县
        /// </summary>
        /// <param name="CityCode">市区域码</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetArea(int CityCode) {
            try
            {
                return _regionalBll.GetArea(CityCode);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetArea服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据县区域码查询县信息
        /// </summary>
        /// <param name="AreaCode">县区域码</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetAreaByAreaCode(int AreaCode) {
            try
            {
                return _regionalBll.GetAreaByAreaCode(AreaCode);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetAreaByAreaCode服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据县名查询县信息
        /// </summary>
        /// <param name="AreaName">县名称</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetAreaByAreaName(string AreaName) {
            try
            {
                return _regionalBll.GetAreaByAreaName(AreaName);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetAreaByAreaName服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
    }
}
